//
//  UIView+InitWithMargin.m
//  TravelGuideMdd
//
//  Created by 陈曦 on 13-5-13.
//  Copyright (c) 2013年 mafengwo.com. All rights reserved.
//

#import "UIView+InitWithMargin.h"

@implementation UIView(InitWithMargin)

- (void)setMarginL:(BOOL)aMarginLeft
                 T:(BOOL)aMarginTop
                 R:(BOOL)aMarginRight
                 B:(BOOL)aMarginBottom
                 W:(BOOL)aWidth
                 H:(BOOL)aHeight
{
    UIViewAutoresizing resize = UIViewAutoresizingNone;
    if (aMarginLeft)
    {
        resize |= UIViewAutoresizingFlexibleLeftMargin;
    }
    if (aMarginTop)
    {
        resize |= UIViewAutoresizingFlexibleTopMargin;
    }
    if (aMarginRight)
    {
        resize |= UIViewAutoresizingFlexibleRightMargin;
    }
    if (aMarginBottom)
    {
        resize |= UIViewAutoresizingFlexibleBottomMargin;
    }
    if (aWidth)
    {
        resize |= UIViewAutoresizingFlexibleWidth;
    }
    if (aHeight)
    {
        resize |= UIViewAutoresizingFlexibleHeight;
    }
    self.autoresizingMask = resize;
}

- (id)initWithFrameX:(CGFloat)aX Y:(CGFloat)aY W:(CGFloat)aW H:(CGFloat)aH
{
    self = [self initWithFrame:CGRectMake(aX,aY,aW,aH)];
    return self;
}

- (id)initWithFrameX:(CGFloat)aX
                   Y:(CGFloat)aY
                   W:(CGFloat)aW
                   H:(CGFloat)aH
             marginL:(BOOL)aMarginLeft
                   T:(BOOL)aMarginTop
                   R:(BOOL)aMarginRight
                   B:(BOOL)aMarginBottom
                   W:(BOOL)aWidth
                   H:(BOOL)aHeight
{
    self = [self initWithFrameX:aX Y:aY W:aW H:aH];
    if (self)
    {
        [self setMarginL:aMarginLeft
                       T:aMarginTop
                       R:aMarginRight
                       B:aMarginBottom
                       W:aWidth
                       H:aHeight];
    }
    return self;
}

- (id)initWithFrame:(CGRect)aFrame
            marginL:(BOOL)aMarginLeft
                  T:(BOOL)aMarginTop
                  R:(BOOL)aMarginRight
                  B:(BOOL)aMarginBottom
                  W:(BOOL)aWidth
                  H:(BOOL)aHeight
{
    self = [self initWithFrame:aFrame];
    if (self)
    {
        [self setMarginL:aMarginLeft
                       T:aMarginTop
                       R:aMarginRight
                       B:aMarginBottom
                       W:aWidth
                       H:aHeight];
    }
    return self;
}

@end
